<?php

/**
 * This is the model class for table "{{articles}}".
 *
 * The followings are the available columns in table '{{articles}}':
 * @property integer $page_id
 * @property string $page_type
 * @property string $page_title
 * @property string $page_date
 * @property string $page_image
 * @property string $page_short_content
 * @property string $page_full_content
 * @property integer $page_active
 * @property string $page_url
 * @property string $page_template
 */
class Articles extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{articles}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('page_type, page_title, page_date, page_url', 'required'),
			array('page_active', 'numerical', 'integerOnly'=>true),
			array('page_type', 'length', 'max'=>8),
			array('page_title, page_image, page_url', 'length', 'max'=>255),
			array('page_short_content', 'length', 'max'=>1024),
			array('page_full_content', 'length', 'max'=>2048),
			array('page_template', 'length', 'max'=>2044),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('page_id, page_type, page_title, page_date, page_image, page_short_content, page_full_content, page_active, page_url, page_template', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'page_id' => 'Page',
			'page_type' => 'Page Type',
			'page_title' => 'Page Title',
			'page_date' => 'Page Date',
			'page_image' => 'Page Image',
			'page_short_content' => 'Page Short Content',
			'page_full_content' => 'Page Full Content',
			'page_active' => 'Page Active',
			'page_url' => 'Page Url',
			'page_template' => 'Page Template',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('page_id',$this->page_id);
		$criteria->compare('page_type',$this->page_type,true);
		$criteria->compare('page_title',$this->page_title,true);
		$criteria->compare('page_date',$this->page_date,true);
		$criteria->compare('page_image',$this->page_image,true);
		$criteria->compare('page_short_content',$this->page_short_content,true);
		$criteria->compare('page_full_content',$this->page_full_content,true);
		$criteria->compare('page_active',$this->page_active);
		$criteria->compare('page_url',$this->page_url,true);
		$criteria->compare('page_template',$this->page_template,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Articles the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
